package com.shoulder.boot.acl.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shoulder.boot.acl.dto.RoleQueryDTO;
import com.shoulder.boot.acl.entity.Role;
import com.shoulder.boot.acl.vo.RoleVo;
import com.shoulder.mybatis.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

public class RoleUtils implements PageUtils<Role, RoleVo> {

    public static RoleUtils buildUtils() {
        return new RoleUtils();
    }

    @Override
    public RoleVo toVo(Role role) {
        RoleVo roleVo = new RoleVo();
        BeanUtils.copyProperties(role, roleVo);
        return roleVo;
    }

    public static LambdaQueryWrapper<Role> buildQueryWrapper(RoleQueryDTO queryDTO) {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<Role>().orderByDesc(Role::getCreateTime);
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getName()), Role::getName, queryDTO.getName());
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getCode()), Role::getCode, queryDTO.getCode());
        queryWrapper.eq(!ObjectUtils.isEmpty(queryDTO.getTenantId()), Role::getTenantId, queryDTO.getTenantId());
        return queryWrapper;
    }
}
